<jsp:useBean id="sessiondata" class="bibbletex.models.SessionData"
	scope="session" />

<%@ page import="bibbletex.models.Collaboration, bibbletex.models.Reference,java.util.UUID,java.util.List,java.util.Collections"
	import="bibbletex.views.CollaborationView,bibbletex.controllers.CollaborationController, bibbletex.views.ReferenceView"%>

<%
	String page_title;
	String onloadjsfunction = "changeAttributes('new',false)";
	String onchangeformjscode="changeAttributes('new',false)";
	Collaboration c;
	String id_parameter = request.getParameter("cid");
	String sorting = request.getParameter("sorting");
	String message_parameter = request.getParameter("message");
	boolean show_library = true;
	int counter = 0;
	boolean show_navigation = false;
	String[] jstitle={"collab"};

	if (id_parameter == null) {
		page_title = new String("Collaboration saved!");
		c = sessiondata.collaboration;
	} else {
		page_title = new String("Show collaboration");

		// the collaboration is editable if it was already editable and the public ID matches
		// (prevents changing from a previously editable collaboration to a new suggestion-only
		// collaboration)
		// or if the id parameter is simply the private id
		sessiondata.collaboration_is_editable = (sessiondata.collaboration_is_editable && sessiondata.collaboration
				.getPublic_id().toString().equals(id_parameter))
				|| Collaboration.id_is_private(id_parameter);

		c = CollaborationController.load(id_parameter);
		sessiondata.collaboration = c;
	}
	if (c != null){
		show_navigation = true;
	}
	else{
		show_navigation = false;
	}

	if (request.getParameter("show_references") != null
			&& request.getParameter("show_references").equals(
					"suggestions"))
		show_library = false;
%>

<%! boolean show_title = true;%>
<%@ include file="/header.jsp"%>

<div id="Content">
	<div id="ContentCenter" class="clearfix">

		<%
			if (c != null) {
			String temp = c.getDescription();
			temp  = temp.replace('\t', ' ');
			// Zeilenumbruch entfernen (Unix)
			temp  = temp.replace('\r', ' ');	
			// Zeilenumbruch/Wagenrücklauf entfernen (Windows)
			temp  = temp.replace('\n', ' ');
		%>

	<div id="Collaboration">
		<% if (message_parameter != null && !message_parameter.equals("")) { %>
		<div class="message-parameter"><%=message_parameter %></div>
		<% } %>
		<div class="info">
			<h1><%=c.getTitle() %></h1>
			<em>
			by
			<a href="mailto:<%=c.getEmail()%>" title="Contact the Author"><%=c.getCreator_name()%></a>
			</em>
			<p id="infoDescription">
			<% if(c.getDescription().length() > 150) {%>
			
			<%=c.getDescription().substring(0,150)%>... <strong onclick="showMore('<%=c.getDescription()%>')">more</strong>
				
			
			 <% } else { %>
			 <%=c.getDescription()%>
			 <% } %>
			</p>
		</div>
		<div class="seperator"></div>

		
		<div class="referenceNavigation clearfix"><ul>
			<li id="libraryTab" class="current">
				<a href="javascript:void(0)" onclick="returnreferences('title', 'show_references=library', false)">Library</a>
			</li> 
			<li id="suggestionsTab">
				<a href="javascript:void(0)" onclick="returnreferences('title', 'show_references=suggestions', false)">Suggestions</a>
			</li>
		</ul></div>
		<div id="referenceContainer" class="clearfix">
			<div class="search">
				<form action="searchreferences.jsp"  onsubmit="searchItem();return false" method="post" name="searchform">
				<input name="searchterm" type="text" placeholder="search" id="Search" />
				<input type="submit" style="display:none;" name="search" value="send" />
				</form>
			</div>
			<div class="headColumn clearfix">
				<div class="type<% if (!sessiondata.collaboration_is_editable){ %> public<% } %>"><a href="javascript:void(0)" onclick="orderby('type', showingtab)">Type <span id="referencetabletypearrow"></span></a></div>
				<div class="title<% if (!sessiondata.collaboration_is_editable){ %> public<% } %>"><a href="javascript:void(0)" onclick="orderby('title', showingtab)">Title <span id="referencetabletitlearrow"></span></a></div>
				<div class="author<% if (!sessiondata.collaboration_is_editable){ %> public<% } %>"><a href="javascript:void(0)" onclick="orderby('author', showingtab)">Author <span id="referencetableauthorarrow"></span></a></div>
				<div class="rating<% if (!sessiondata.collaboration_is_editable){ %> public<% } %>"><a href="javascript:void(0)" onclick="orderby('relevance', showingtab)">Relevance <span id="referencetablerelevancearrow"></span></a></div>
			</div>
			<form action="/collaboration/export.jsp" name="references" method="post">

				<div id="resultreferences"></div>
				<% if (sessiondata.collaboration_is_editable){ %>
				<input type="hidden" name="exportselectedrefs" id="exportselectedrefs" value="" />
				<a class="buttonExport clearfix" style="float:left;" href="#" onclick="document.getElementById('exportselectedrefs').value='true';document.references.submit()"><canvas id="exportReference" width="50" height="50"></canvas> <em>Export selected references</em>

				</a>
				<% } %>
				<a class="<% if (!sessiondata.collaboration_is_editable){ %>buttonexport<% } else{%>button<% }%> clearfix" href="#" onclick="showPopUp(); return false;"><canvas id="addReference" width="50" height="50"></canvas> <em><%=CollaborationView
							.possible_action(sessiondata.collaboration_is_editable)%>
						a Reference</em>
				</a>
			</div>
			</div>
		
			
			</form>
			
			

			<%
				} else {
			%>

			<div class="error">Unable to load Collaboration.
			<br />Please Contact our Support.</div>

			<%
				}
			%>
			</div>
		</div>
	
	<script type="text/javascript" src="/js/reference.js"></script>
	
	<div id="darken" style="display:none;" onclick="closePopUp(); closePopUp2();">
		
	</div>	
	<div id="popup" style="display:none;">
				<h1>Add a new Reference</h1>
				<jsp:include page="/collaboration/reference/new.jsp">
					<jsp:param value="new" name="formprefix"/>
				</jsp:include>	
				
	</div>	
	
	<div id="popup2" style="display:none;">
		
				
				
	</div>

	<%@ include file="/footer.jsp"%>
